import 'package:base_flutter/base_flutter.dart';
import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:ls_work/net/response/visitor_check/visitor_check_list_data.dart';
import 'package:ls_work/ui/visitor_check/visitor_check_detail_page.dart';
import 'package:ls_work/viewmodel/visitor_check/visitor_check_list_view_model.dart';
import 'package:ls_work/widgets/dotted_line.dart';

class VisitorCheckListPage extends BaseStatefulMvvmWidget {
  @override
  State<StatefulWidget> createState() => _VisitorCheckListState();
}

class _VisitorCheckListState
    extends BaseMvvmListState<VisitorCheckListViewModel, VisitorCheckListPage> {
  @override
  Widget buildRootView(BuildContext context, Widget loadingContentWidget) {
    return Scaffold(
      appBar: AppBar(
        title: Text('访客审核'),
      ),
      body: loadingContentWidget,
    );
  }

  @override
  Widget createItemWidget(int index) {
    var item = viewModel.listItems[index];
    return index == 0 ? Column(
      children: [
        Row(
          children: [
            CommonText('预约来访时间', fontWeight: FontWeight.bold,
                textAlign: TextAlign.center,textSize: 14).setWeight(1),
            CommonText(
                '来访人', fontWeight: FontWeight.bold, textAlign: TextAlign.center,textSize: 14)
                .setWeight(1),
            CommonText('被来访人', fontWeight: FontWeight.bold,
                textAlign: TextAlign.center,textSize: 14).setWeight(1),
            CommonText('审核状态', fontWeight: FontWeight.bold,
                textAlign: TextAlign.center,textSize: 14).setWeight(1),
          ],
        ),
        Container(height: 5,),
        itemWid(item)
      ],
    ) : itemWid(item);
  }


  Widget itemWid(VisitorCheckListData item) {
    return Row(
      children: [
        CommonText(
            item.date, textAlign: TextAlign.center,textSize: 14)
            .setWeight(1),
        CommonText(
            item.name, textAlign: TextAlign.center,textSize: 14)
            .setWeight(1),
        CommonText(
            item.old,  textAlign: TextAlign.center,textSize: 14)
            .setWeight(1),
        CommonText(
            item.status,textAlign: TextAlign.center,textSize: 14)
            .setWeight(1),
      ],
    ).addToContainer(margin: EdgeInsets.symmetric(vertical: 13))
    .onTap(() {
      Go().push(VisitorCheckDetailPage(item));
    });
  }

  @override
  VisitorCheckListViewModel createViewModel() {
    return VisitorCheckListViewModel(context);
  }

  @override
  EdgeInsets get listPadding => EdgeInsets.symmetric(horizontal: 16,vertical: 15);

  @override
  Widget get separatorDivider => DottedLine(color: Colors.grey,);
}
